<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <script src="../js/axios.min.js"></script>
    <script src="../js/api.js"></script>

    <link rel="stylesheet" href="../css/dl.css" />
  </head>
  <body>
    <div class="head">
      <div class="head-warp">
        <div class="logo">
          <img src="../images/img-login/logo.png" alt="" />
        </div>
        <div class="head-right">
          <ul>
            <li><a href="http://www.secoo.com/"> 寺库首页</a></li>
            <li><a href=""> 收藏寺库</a></li>
            <li>
              <a href="http://www.secoo.com/special/sikuApp.shtml"> 寺库APP</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="dnav">
      <div class="nav">
        <div class="right-ipt">
          <div class="x">
            <p>用户</p>
            <input
              type="text"
              placeholder="请输入手机号码或邮箱"
            /><span></span> <br />
            <p>密码</p>
            <input type="password" /><span></span> <br />
          </div>
          <div class="y"><input type="checkbox" /><span>记住账号</span></div>
          <button>立即登录</button>
          <div class="a">第三方登录</div>
          <div class="o">
            <p>
              <img src="../images/img-login/qq.jpg" alt="" />
              <a
                href="https://graph.qq.com/oauth2.0/show?which=Login&display=pc&response_type=code&client_id=223136&redirect_uri=https://passport.secoo.com/login/Logic_login.jsp?command=QQLOGIN&state=https://www.secoo.com/&scope="
                >qq</a
              >
            </p>
            <div class="b">
              <p>
                <img src="../images/img-login/WeChat.png" alt="" /><a
                  href="https://open.weixin.qq.com/connect/qrconnect?appid=wx01d0dc14f8acf49d&response_type=code&scope=snsapi_login&redirect_uri=https://passport.secoo.com/login/Logic_login.jsp?command=WXLOGIN&state=https://www.secoo.com/#wechat_redirect"
                  >微信</a
                >
              </p>
            </div>
            <div class="c">
              <p>还没注册？<a href="../html/zc.html">立即注册</a></p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script>
      let ipts = document.querySelectorAll(".x input");
      let btn = document.querySelector("button");
      let span = document.querySelectorAll("span");
      let isUsername = false;
      let isPassword = false;
      ipts[0].onchange = function () {
        let yz =
          /^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$|^\w+@(126|163|qq)+\.com$/;
        let a = this.value;
        console.log(a);
        if (yz.test(this.value)) {
          isUsername = true;
        } else {
          isUsername = false;
          span[0].innerHTML = "账号错误";
        }
        console.log(isUsername);
      };
      ipts[1].onchange = () => {
        let zz = /^\w{6,12}$/;
        if (zz.test(this.value)) {
          isPassword = true;
        } else {
          isPassword = false;
          span[1].innerHTML = "密码错误";
        }
      };
      btn.onclick = () => {
        console.log("1");
        if (isUsername == true && isPassword == true) {
          let username = ipts[0].value;
          let password = ipts[1].value;
          console.log(2);
          console.log(username);
          console.log(password);
          axios
            .get(loginAPI, {
              params: {
                username,
                password,
              },
            })
            .then((res) => {
              console.log(res);
              obj = res.data;
              console.log(obj);
              localStorage.setItem("uid", obj.data.id);
              localStorage.setItem("useranme", obj.data.username);
              localStorage.setItem("token", obj.data.token);
              alert(obj.msg);
              if (obj.code == 1) {
                location.href = "index.html";
              }
            });
        }
      };
    </script>
  </body>
</html>
